perm filename BUG.MF[MF,DEK] blob sn#756251 filedate 1984-05-26 generic text, type T, neo UTF8
% My borders for CS 279.
% 
% The border represents a ribbon, which has been twisted around the page.
% The ribbon is made of 11 parallel lines which cross over to represent
% the twisting of the ribbon.
%
% Author: Bruce Leban
% Last updated: 5/19/84
% Status: incomplete

input bbase
sunrules;
scale = 1;	% set to other values for larger or smaller borders
proofing := 1;

def down  = (0,-1) enddef;
def up    = (0,1)  enddef;
def right = (1,0)  enddef;
def left  = (-1,0) enddef;

% sizes of border components
% NOTE - these values are only for testing on the Sun

M.height = M.width  = 1/2in*scale;
N.height = S.height = W.width = E.width = 20 pensize = 1/8in*scale;

M.twist = 1/4 M.height;	% heuristic value (produces nice curves)

pen drawpen;  drawpen  := pencircle scaled pensize;
pen erasepen; erasepen := pencircle scaled 1.3pensize;

% definitions of border characters

def drawpathp =
	draw p withpen erasepen withweight -1;
	cullit; 
	draw p withpen drawpen;
	cullit; showit;
enddef;

vardef t@# = (tx@#,ty@#) enddef;

vardef twist (expr xleft,yleft,xright,yright,twist_width)(text dir) =
	begingroup
	numeric tx[],ty[];

	t1 = (xleft,yleft);
	t2 = (1/2[xright, xleft] - twist_width, yleft);
	t3 = (1/2[xright, xleft] + twist_width, yright);
	t4 = (xright,yright);
	path p;
	p = t1 {dir} .. t2 {dir} .. t3 {dir} .. t4 {dir};
	drawpathp;
	endgroup
enddef;

vardef curvedturn (expr xvert,yvert,xhoriz,yhoriz)
	    (text leftdir,rightdir)(expr theta) =
	begingroup
	path p;
	p = (xvert,yvert)	{leftdir rotated theta} 
	    .. (xhoriz,yhoriz)	{rightdir rotated -theta};
	drawpathp;
	endgroup
enddef;
	
vardef foldedturn (expr xvert,yvert,xhoriz,yhoriz) =
	begingroup
	path p;
	p = (xvert,yvert) .. (xhoriz,yvert) & 
	    (xhoriz,yvert) .. (xhoriz,yhoriz);
	tracingonline := 1;
	showall p;
	draw p withpen drawpen;
	%drawpathp;
	endgroup;
enddef;

vardef char.N.M =
	for i := 0 step .1 until 1.0001:     % .0001 is because of MF bug
	   twist (0, i*N.height,		% left side
		  M.width, (1-i)*N.height,	% right side
		  M.twist)			% degree of twist
		  (right);			% going left to right
	endfor;
enddef;
	
vardef char.N.E =
	for i := 0 step .1 until 1.0001:
	   curvedturn (0, i*N.height,	% left side
		      i*E.width, 0)	% down side
		      (right)(down)	% directions at end points
		      (0);		% don't tilt directions 
	endfor;
enddef;

vardef char.S.E =
	for i := 0 step .1 until 1.0001:
	   foldedturn (0, i*S.height,		% left side
		       i*E.width, S.height);	% up side
	endfor;
enddef;
		
%pausing := 1;
def tracingall=tracingcommands:=3;
 tracingedges:=1; tracingtitles:=1; tracingequations:=1; tracingspecs:=1;
	tracingpens:=1; tracingchoices:=1; tracingstats:=2;
 tracingonline:=1;tracingoutput:=1;tracingmacros:=3; xyzzy:=1 enddef;
tracingall;
%test N.M;
%test N.E;
 test S.E;
end